package com.future.baselib.entity;

import android.text.TextUtils;

import com.future.baselib.utils.JLog;
import com.future.baselib.utils.LogUtils;

import org.json.JSONException;
import org.json.JSONObject;

public class RongResponse {

    public int returnNo = -1;
    public String erroMessage;
    public String token;

    public void parseJson(String json, int code) {
        JLog.e("json", "json --- " + json);
        JLog.e("json", "code --- " + code);
        try {
            if (TextUtils.isEmpty(json)) {
                returnNo = code;
                if (returnNo == 500)
                    erroMessage = "服务器链接失败";
                else if (returnNo == 404)
                    erroMessage = "链接失效";
                else if (returnNo == 405)
                    erroMessage = "不支持的请求资源";
                else if (returnNo == 403)
                    erroMessage = "未授权";
                else if (returnNo == 503)
                    erroMessage = "服务器正在维护";
                return;
            }
            JSONObject object = new JSONObject(json);
            returnNo = object.optInt("code", -1);
            if (returnNo == 200) {
                token = object.optString("token");
            } else {
                erroMessage = String.valueOf(returnNo);
            }
        } catch (JSONException e) {
            LogUtils.e("BaseResponse", "json格式有误:" + json);
        }
    }


}
